package krow.dev.gunpobus.view.adapter;

import java.util.ArrayList;
import java.util.List;

import krow.dev.gunpobus.model.RouteItem;
import krow.dev.gunpobus.util.ItemViewFactory;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class RouteListAdapter extends BaseAdapter{

	private LayoutInflater mLayoutInflater;

	private List<RouteItem> mRouteItemList;
	
	public RouteListAdapter(Context context) {
		
		mLayoutInflater = LayoutInflater.from(context);
		
		mRouteItemList = new ArrayList<RouteItem>();
	}
	
	public void setRouteItemList(List<RouteItem> routeItemList){
		
		mRouteItemList.clear();
		mRouteItemList.addAll(routeItemList);
	}
	
	public void clear(){
		
		mRouteItemList.clear();
	}
	
	@Override
	public int getCount() {
		
		return mRouteItemList.size();
	}

	@Override
	public Object getItem(int position) {

		return mRouteItemList.get(position);
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		RouteItem routeItem = mRouteItemList.get(position);
		
		View view = ItemViewFactory.createRouteView(
				mLayoutInflater, 
				routeItem.getName(), 
				routeItem.getType(), 
				routeItem);
		
		return view;
	}
}
